#!/usr/bin/env python
#coding:utf-8
#author: mooder@gmail.com
from django.db import models

# Create your models here.
class Userinfo(models.Model):
    name = models.CharField(u'姓名', max_length=20)
    mobile = models.CharField(u'电话', max_length=20)
    password = models.CharField(u'密码', max_length=20)

    address = models.CharField(u'地址', max_length=50)
    note = models.CharField(u'备注', max_length=100)

    create_at = models.DateTimeField(u'创建时间', auto_now_add=True)
    update_at = models.DateTimeField(u'创建时间', auto_now_add=True)

    #create_by = models.ForeignKey(User)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name    = u'用户'
        verbose_name_plural = u'用户'
        ordering        = ('update_at',)

COOK_TYPE = (
        (0, u'其它'),
        (1, u'烧'),
        (2, u'炒'),
        (3, u'炖'),
        (4, u'凉拌'),
        (5, u'煮'),
        (6, u'蒸'),
        )

DISH_TYPE = (
        (0, u'其它'),
        (1, u'热菜'),
        (2, u'凉菜'),
        (3, u'主食'),
        (4, u'下午茶'),
        (5, u'果盘'),
        )

PREFER_TYPE = (
        (0, u'未描述'),
        (1, u'普通'),
        (2, u'清淡'),
        (3, u'咸'),
        (4, u'辣'),
        (5, u'海鲜'),
        )

class Dish(models.Model):
    name = models.CharField(u'菜名', max_length=20)
    material = models.CharField(u'食材', max_length=50)
    cooktype= models.IntegerField(u'烹饪方法', default=0, choices=COOK_TYPE)
    type = models.IntegerField(u'类型', default=0, choices=DISH_TYPE)
    prefer = models.IntegerField(u'口味', default=0, choices=PREFER_TYPE)
    pic_small = models.ImageField(u'小图', upload_to='upload/art/s', blank=True)
    detail = models.TextField(u'说明', max_length=200)
    price = models.IntegerField(u'价格', max_length=200)
    function = models.TextField(u'功效', max_length=200)
    create_at = models.DateTimeField(u'创建时间', auto_now_add=True)
    update_at = models.DateTimeField(u'更新时间', auto_now=True)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name    = u'菜品'
        verbose_name_plural = u'菜品'
        ordering        = ('update_at',)

MEAL_TYPE = (
        (1, u'中餐'),
        (2, u'下午茶'),
        (3, u'晚餐'),
        )

STATUS_CHOICE = (
        (0, u'在售'),
        (1, u'售罄'),
        )
class Package(models.Model):
    name = models.CharField(u'名称', max_length=20)
    date_deal = models.DateField(u'日期')
    meal_type = models.IntegerField(u'餐种', choices=MEAL_TYPE)
    content = models.ManyToManyField(Dish, blank=False, verbose_name=u'菜品')
    price = models.IntegerField(u'价格', default=16)
    status = models.IntegerField(u'状态', default=0, choices=STATUS_CHOICE)
    inventory = models.IntegerField(u'存量', default=99)

    create_at = models.DateTimeField(u'创建时间', auto_now_add=True)
    update_at = models.DateTimeField(u'更新时间', auto_now=True)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name    = u'菜单'
        verbose_name_plural = u'菜单'
        ordering        = ('update_at',)

ORDER_STATUS = (
            (0,u'新订单'),
            (1,u'已确认'),
            (2,u'送餐中'),
            (3,u'已送达'),
        )

class Order(models.Model):
    user = models.ForeignKey(Userinfo)
    cart = models.ManyToManyField(Package)
    remark = models.CharField(u'备注',blank=True, max_length=20)
    expect = models.TimeField(u'期望时间')
    status = models.IntegerField(u'状态', default=0, choices=ORDER_STATUS)
    create_at = models.DateTimeField(u'创建时间', auto_now_add=True)
    update_at = models.DateTimeField(u'更新时间', auto_now=True)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name    = u'订单'
        verbose_name_plural = u'订单'
        ordering        = ('update_at',)


